<template>
  <div class="product-card">
    <img :src="product.image" :alt="product.name" class="product-image" />
    <div class="product-info">
      <h3>{{ product.name }}</h3>
      <p>价格: {{ product.price }}</p>
      <p>销量: {{ product.sales }}</p>
      <p>评论数: {{ product.comments }}</p>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { defineProps } from 'vue'

  defineProps<{
    product: {
      id: number
      image: string
      name: string
      price: number
      sales: number
      comments: number
      isAd: boolean
    }
  }>()
</script>

<style scoped>
  .product-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 200px; /* 设置商品卡片的宽度 */
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden; /* 防止内容溢出容器 */
    position: relative;
    height: 100%; /* 确保卡片高度可调整 */
  }

  .product-image {
    flex: 4; /* 占用卡片高度的 4/5 */
    width: 100%;
    object-fit: cover; /* 确保图片填满容器，多余部分裁剪 */
    border-radius: 8px; /* 圆角样式 */
    transition: transform 0.3s ease; /* 平滑过渡 */
    cursor: pointer; /* 鼠标悬停时显示指针 */
  }

  .product-image:hover {
    transform: scale(1.2); /* 鼠标悬停时放大为1.2倍 */
  }

  .product-info {
    flex: 1; /* 占用卡片高度的 1/5 */
    padding: 10px; /* 为文字部分添加内边距 */
    text-align: center;
  }

  .product-info h3 {
    font-size: 16px;
    font-weight: bold;
  }

  .product-info p {
    margin: 5px 0;
    color: #666;
  }

  .product-info p.price {
    color: red; /* 价格突出显示 */
    font-weight: bold;
  }
</style>
